<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActionController::Assertions::ResponseAssertions</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActionController::Assertions::ResponseAssertions</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/rails/actionpack/lib/action_controller/assertions/response_assertions_rb.html">
                vendor/rails/actionpack/lib/action_controller/assertions/response_assertions.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
A small suite of assertions that test responses from <a
href="../../Rails.html">Rails</a> applications.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000355">assert_redirected_to</a>&nbsp;&nbsp;
      <a href="#M000354">assert_response</a>&nbsp;&nbsp;
      <a href="#M000356">assert_template</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000355" class="method-detail">
        <a name="M000355"></a>

        <div class="method-heading">
          <a href="#M000355" class="method-signature">
          <span class="method-name">assert_redirected_to</span><span class="method-args">(options = {}, message=nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Assert that the redirection options passed in match those of the redirect
called in the latest action. This match can be partial, such that <a
href="ResponseAssertions.html#M000355">assert_redirected_to</a>(:controller
=&gt; &quot;weblog&quot;) will also match the redirection of
redirect_to(:controller =&gt; &quot;weblog&quot;, :action =&gt;
&quot;show&quot;) and so on.
</p>
<h4>Examples</h4>
<pre>
  # assert that the redirection was to the &quot;index&quot; action on the WeblogController
  assert_redirected_to :controller =&gt; &quot;weblog&quot;, :action =&gt; &quot;index&quot;

  # assert that the redirection was to the named route login_url
  assert_redirected_to login_url
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000355-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000355-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/assertions/response_assertions.rb, line 53</span>
 53:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assert_redirected_to</span>(<span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">message</span>=<span class="ruby-keyword kw">nil</span>)
 54:         <span class="ruby-identifier">clean_backtrace</span> <span class="ruby-keyword kw">do</span>
 55:           <span class="ruby-identifier">assert_response</span>(<span class="ruby-identifier">:redirect</span>, <span class="ruby-identifier">message</span>)
 56:           <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span> <span class="ruby-operator">==</span> <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">redirected_to</span>
 57:           <span class="ruby-constant">ActionController</span><span class="ruby-operator">::</span><span class="ruby-constant">Routing</span><span class="ruby-operator">::</span><span class="ruby-constant">Routes</span>.<span class="ruby-identifier">reload</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">ActionController</span><span class="ruby-operator">::</span><span class="ruby-constant">Routing</span><span class="ruby-operator">::</span><span class="ruby-constant">Routes</span>.<span class="ruby-identifier">empty?</span>
 58: 
 59:           <span class="ruby-keyword kw">begin</span>
 60:             <span class="ruby-identifier">url</span>  = {}
 61:             <span class="ruby-identifier">original</span> = { <span class="ruby-identifier">:expected</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">options</span>, <span class="ruby-identifier">:actual</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">redirected_to</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>) <span class="ruby-operator">?</span> <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">redirected_to</span> <span class="ruby-operator">:</span> <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">redirected_to</span>.<span class="ruby-identifier">dup</span> }
 62:             <span class="ruby-identifier">original</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
 63:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>)
 64:                 <span class="ruby-identifier">value</span> = <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">value</span>, <span class="ruby-keyword kw">true</span>) <span class="ruby-operator">?</span> <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">value</span>) <span class="ruby-operator">:</span> <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;hash_for_#{value}_url&quot;</span>)
 65:               <span class="ruby-keyword kw">end</span>
 66: 
 67:               <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
 68:                 <span class="ruby-identifier">request</span> = <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">value</span>
 69:                   <span class="ruby-keyword kw">when</span> <span class="ruby-constant">NilClass</span>    <span class="ruby-keyword kw">then</span> <span class="ruby-keyword kw">nil</span>
 70:                   <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/^\w+:\/\//</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">recognized_request_for</span>(<span class="ruby-regexp re">%r{^(\w+://.*?(/|$|\?))(.*)$}</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">value</span> <span class="ruby-value">? </span><span class="ruby-identifier">$3</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>)
 71:                   <span class="ruby-keyword kw">else</span>                  <span class="ruby-identifier">recognized_request_for</span>(<span class="ruby-identifier">value</span>)
 72:                 <span class="ruby-keyword kw">end</span>
 73:                 <span class="ruby-identifier">value</span> = <span class="ruby-identifier">request</span>.<span class="ruby-identifier">path_parameters</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">request</span>
 74:               <span class="ruby-keyword kw">end</span>
 75: 
 76:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-comment cmt"># stringify 2 levels of hash keys</span>
 77:                 <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">name</span> = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:use_route</span>)
 78:                   <span class="ruby-identifier">route</span> = <span class="ruby-constant">ActionController</span><span class="ruby-operator">::</span><span class="ruby-constant">Routing</span><span class="ruby-operator">::</span><span class="ruby-constant">Routes</span>.<span class="ruby-identifier">named_routes</span>[<span class="ruby-identifier">name</span>]
 79:                   <span class="ruby-identifier">value</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">route</span>.<span class="ruby-identifier">parameter_shell</span>)
 80:                 <span class="ruby-keyword kw">end</span>
 81: 
 82:                 <span class="ruby-identifier">value</span>.<span class="ruby-identifier">stringify_keys!</span>
 83:                 <span class="ruby-identifier">value</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">select</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) }.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">stringify_keys!</span> }
 84:                 <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:expected</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">value</span>[<span class="ruby-value str">'controller'</span>] <span class="ruby-operator">==</span> <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">controller_name</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">original</span>[<span class="ruby-identifier">:actual</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
 85:                   <span class="ruby-identifier">original</span>[<span class="ruby-identifier">:actual</span>].<span class="ruby-identifier">stringify_keys!</span>
 86:                   <span class="ruby-identifier">value</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">'controller'</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">original</span>[<span class="ruby-identifier">:actual</span>][<span class="ruby-value str">'controller'</span>].<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">original</span>[<span class="ruby-identifier">:actual</span>][<span class="ruby-value str">'controller'</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">value</span>[<span class="ruby-value str">'controller'</span>]
 87:                 <span class="ruby-keyword kw">end</span>
 88:               <span class="ruby-keyword kw">end</span>
 89: 
 90:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:[]</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">value</span>[<span class="ruby-value str">'controller'</span>]
 91:                 <span class="ruby-identifier">value</span>[<span class="ruby-value str">'controller'</span>] = <span class="ruby-identifier">value</span>[<span class="ruby-value str">'controller'</span>].<span class="ruby-identifier">to_s</span>
 92:                 <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:actual</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">value</span>[<span class="ruby-value str">'controller'</span>].<span class="ruby-identifier">first</span> <span class="ruby-operator">!=</span> <span class="ruby-value str">'/'</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">value</span>[<span class="ruby-value str">'controller'</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-value str">'/'</span>)
 93:                   <span class="ruby-identifier">new_controller_path</span> = <span class="ruby-constant">ActionController</span><span class="ruby-operator">::</span><span class="ruby-constant">Routing</span>.<span class="ruby-identifier">controller_relative_to</span>(<span class="ruby-identifier">value</span>[<span class="ruby-value str">'controller'</span>], <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">controller_path</span>)
 94:                   <span class="ruby-identifier">value</span>[<span class="ruby-value str">'controller'</span>] = <span class="ruby-identifier">new_controller_path</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>[<span class="ruby-value str">'controller'</span>] <span class="ruby-operator">!=</span> <span class="ruby-identifier">new_controller_path</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">ActionController</span><span class="ruby-operator">::</span><span class="ruby-constant">Routing</span>.<span class="ruby-identifier">possible_controllers</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">new_controller_path</span>)
 95:                 <span class="ruby-keyword kw">end</span>
 96:                 <span class="ruby-identifier">value</span>[<span class="ruby-value str">'controller'</span>] = <span class="ruby-identifier">value</span>[<span class="ruby-value str">'controller'</span>][<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>[<span class="ruby-value str">'controller'</span>].<span class="ruby-identifier">first</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'/'</span> <span class="ruby-comment cmt"># strip leading hash</span>
 97:               <span class="ruby-keyword kw">end</span>
 98:               <span class="ruby-identifier">url</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>
 99:             <span class="ruby-keyword kw">end</span>
100: 
101:             <span class="ruby-ivar">@response_diff</span> = <span class="ruby-identifier">url</span>[<span class="ruby-identifier">:actual</span>].<span class="ruby-identifier">diff</span>(<span class="ruby-identifier">url</span>[<span class="ruby-identifier">:expected</span>]) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">url</span>[<span class="ruby-identifier">:actual</span>]
102:             <span class="ruby-identifier">msg</span> = <span class="ruby-identifier">build_message</span>(<span class="ruby-identifier">message</span>, <span class="ruby-value str">&quot;expected a redirect to &lt;?&gt;, found one to &lt;?&gt;, a difference of &lt;?&gt; &quot;</span>, <span class="ruby-identifier">url</span>[<span class="ruby-identifier">:expected</span>], <span class="ruby-identifier">url</span>[<span class="ruby-identifier">:actual</span>], <span class="ruby-ivar">@response_diff</span>)
103: 
104:             <span class="ruby-identifier">assert_block</span>(<span class="ruby-identifier">msg</span>) <span class="ruby-keyword kw">do</span>
105:               <span class="ruby-identifier">url</span>[<span class="ruby-identifier">:expected</span>].<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">all?</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
106:                 <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">k</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:controller</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">url</span>[<span class="ruby-identifier">:expected</span>][<span class="ruby-identifier">k</span>] <span class="ruby-operator">==</span> <span class="ruby-constant">ActionController</span><span class="ruby-operator">::</span><span class="ruby-constant">Routing</span>.<span class="ruby-identifier">controller_relative_to</span>(<span class="ruby-identifier">url</span>[<span class="ruby-identifier">:actual</span>][<span class="ruby-identifier">k</span>], <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">controller_path</span>)
107:                 <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">parameterize</span>(<span class="ruby-identifier">url</span>[<span class="ruby-identifier">:expected</span>][<span class="ruby-identifier">k</span>]) <span class="ruby-operator">==</span> <span class="ruby-identifier">parameterize</span>(<span class="ruby-identifier">url</span>[<span class="ruby-identifier">:actual</span>][<span class="ruby-identifier">k</span>])
108:                 <span class="ruby-keyword kw">end</span>
109:               <span class="ruby-keyword kw">end</span>
110:             <span class="ruby-keyword kw">end</span>
111:           <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ActionController</span><span class="ruby-operator">::</span><span class="ruby-constant">RoutingError</span> <span class="ruby-comment cmt"># routing failed us, so match the strings only.</span>
112:             <span class="ruby-identifier">msg</span> = <span class="ruby-identifier">build_message</span>(<span class="ruby-identifier">message</span>, <span class="ruby-value str">&quot;expected a redirect to &lt;?&gt;, found one to &lt;?&gt;&quot;</span>, <span class="ruby-identifier">options</span>, <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">redirect_url</span>)
113:             <span class="ruby-identifier">url_regexp</span> = <span class="ruby-regexp re">%r{^(\w+://.*?(/|$|\?))(.*)$}</span>
114:             <span class="ruby-identifier">eurl</span>, <span class="ruby-identifier">epath</span>, <span class="ruby-identifier">url</span>, <span class="ruby-identifier">path</span> = [<span class="ruby-identifier">options</span>, <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">redirect_url</span>].<span class="ruby-identifier">collect</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">url</span><span class="ruby-operator">|</span>
115:               <span class="ruby-identifier">u</span>, <span class="ruby-identifier">p</span> = (<span class="ruby-identifier">url_regexp</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">url</span>) <span class="ruby-operator">?</span> [<span class="ruby-identifier">$1</span>, <span class="ruby-identifier">$3</span>] <span class="ruby-operator">:</span> [<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">url</span>]
116:               [<span class="ruby-identifier">u</span>, (<span class="ruby-identifier">p</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'/'</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">p</span> <span class="ruby-operator">:</span> <span class="ruby-value str">'/'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">p</span>]
117:             <span class="ruby-keyword kw">end</span>.<span class="ruby-identifier">flatten</span>
118: 
119:             <span class="ruby-identifier">assert_equal</span>(<span class="ruby-identifier">eurl</span>, <span class="ruby-identifier">url</span>, <span class="ruby-identifier">msg</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">eurl</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">url</span>
120:             <span class="ruby-identifier">assert_equal</span>(<span class="ruby-identifier">epath</span>, <span class="ruby-identifier">path</span>, <span class="ruby-identifier">msg</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">epath</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">path</span>
121:           <span class="ruby-keyword kw">end</span>
122:         <span class="ruby-keyword kw">end</span>
123:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000354" class="method-detail">
        <a name="M000354"></a>

        <div class="method-heading">
          <a href="#M000354" class="method-signature">
          <span class="method-name">assert_response</span><span class="method-args">(type, message = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Asserts that the response is one of the following types:
</p>
<ul>
<li><tt>:success</tt> - Status code was 200

</li>
<li><tt>:redirect</tt> - Status code was in the 300-399 range

</li>
<li><tt>:missing</tt> - Status code was 404

</li>
<li><tt>:error</tt> - Status code was in the 500-599 range

</li>
</ul>
<p>
You can also pass an explicit status number like <a
href="ResponseAssertions.html#M000354">assert_response</a>(501) or its
symbolic equivalent <a
href="ResponseAssertions.html#M000354">assert_response</a>(:not_implemented).
See ActionController::StatusCodes for a full list.
</p>
<h4>Examples</h4>
<pre>
  # assert that the response was a redirection
  assert_response :redirect

  # assert that the response code was status code 401 (unauthorized)
  assert_response 401
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000354-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000354-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/assertions/response_assertions.rb, line 27</span>
27:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assert_response</span>(<span class="ruby-identifier">type</span>, <span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>)
28:         <span class="ruby-identifier">clean_backtrace</span> <span class="ruby-keyword kw">do</span>
29:           <span class="ruby-keyword kw">if</span> [ <span class="ruby-identifier">:success</span>, <span class="ruby-identifier">:missing</span>, <span class="ruby-identifier">:redirect</span>, <span class="ruby-identifier">:error</span> ].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">type</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{type}?&quot;</span>)
30:             <span class="ruby-identifier">assert_block</span>(<span class="ruby-value str">&quot;&quot;</span>) { <span class="ruby-keyword kw">true</span> } <span class="ruby-comment cmt"># to count the assertion</span>
31:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">type</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Fixnum</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">response_code</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">type</span>
32:             <span class="ruby-identifier">assert_block</span>(<span class="ruby-value str">&quot;&quot;</span>) { <span class="ruby-keyword kw">true</span> } <span class="ruby-comment cmt"># to count the assertion</span>
33:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">type</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">response_code</span> <span class="ruby-operator">==</span> <span class="ruby-constant">ActionController</span><span class="ruby-operator">::</span><span class="ruby-constant">StatusCodes</span><span class="ruby-operator">::</span><span class="ruby-constant">SYMBOL_TO_STATUS_CODE</span>[<span class="ruby-identifier">type</span>]
34:             <span class="ruby-identifier">assert_block</span>(<span class="ruby-value str">&quot;&quot;</span>) { <span class="ruby-keyword kw">true</span> } <span class="ruby-comment cmt"># to count the assertion</span>
35:           <span class="ruby-keyword kw">else</span>
36:             <span class="ruby-identifier">assert_block</span>(<span class="ruby-identifier">build_message</span>(<span class="ruby-identifier">message</span>, <span class="ruby-value str">&quot;Expected response to be a &lt;?&gt;, but was &lt;?&gt;&quot;</span>, <span class="ruby-identifier">type</span>, <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">response_code</span>)) { <span class="ruby-keyword kw">false</span> }
37:           <span class="ruby-keyword kw">end</span>
38:         <span class="ruby-keyword kw">end</span>
39:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000356" class="method-detail">
        <a name="M000356"></a>

        <div class="method-heading">
          <a href="#M000356" class="method-signature">
          <span class="method-name">assert_template</span><span class="method-args">(expected = nil, message=nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Asserts that the request was rendered with the appropriate template file.
</p>
<h4>Examples</h4>
<pre>
  # assert that the &quot;new&quot; view template was rendered
  assert_template &quot;new&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000356-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000356-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/assertions/response_assertions.rb, line 132</span>
132:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assert_template</span>(<span class="ruby-identifier">expected</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">message</span>=<span class="ruby-keyword kw">nil</span>)
133:         <span class="ruby-identifier">clean_backtrace</span> <span class="ruby-keyword kw">do</span>
134:           <span class="ruby-identifier">rendered</span> = <span class="ruby-identifier">expected</span> <span class="ruby-value">? </span><span class="ruby-ivar">@response</span>.<span class="ruby-identifier">rendered_file</span>(<span class="ruby-operator">!</span><span class="ruby-identifier">expected</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">'/'</span>)) <span class="ruby-operator">:</span> <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">rendered_file</span>
135:           <span class="ruby-identifier">msg</span> = <span class="ruby-identifier">build_message</span>(<span class="ruby-identifier">message</span>, <span class="ruby-value str">&quot;expecting &lt;?&gt; but rendering with &lt;?&gt;&quot;</span>, <span class="ruby-identifier">expected</span>, <span class="ruby-identifier">rendered</span>)
136:           <span class="ruby-identifier">assert_block</span>(<span class="ruby-identifier">msg</span>) <span class="ruby-keyword kw">do</span>
137:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">expected</span>.<span class="ruby-identifier">nil?</span>
138:               <span class="ruby-operator">!</span><span class="ruby-ivar">@response</span>.<span class="ruby-identifier">rendered_with_file?</span>
139:             <span class="ruby-keyword kw">else</span>
140:               <span class="ruby-identifier">expected</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">rendered</span>
141:             <span class="ruby-keyword kw">end</span>
142:           <span class="ruby-keyword kw">end</span>
143:         <span class="ruby-keyword kw">end</span>
144:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>